<html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>
            配置管理器
        </title>
<link rel="stylesheet" href="{{ url_for('dev.static', filename='formbuilder/layui/css/layui.css') }}" />
    {% include 'system/common/header.html' %}
    </head>
<body class="pear-container">

<script type="text/html" id="confItems">
    <div class="layui-row oneline_item">
<div class="layui-col-md11">
  <div class="layui-col-md3">
        <div class="layui-form-item">
            <div class="layui-input-group">
              <div class="layui-input-split layui-input-prefix">
                配置变量
              </div>
              <input type="text"  name="key[]" lay-verify="required" lay-reqtext="变量名必须填写，请填写英文（数字不能开头）" placeholder="请输入" class="layui-input">
            </div>
        </div>
  </div>
      <div class="layui-col-md3">
        <div class="layui-form-item">
            <div class="layui-input-group">
              <div class="layui-input-split layui-input-prefix">
                配置名称
              </div>
              <input type="text"  name="name[]" placeholder="请输入" class="layui-input" lay-verify="required">
            </div>
        </div>
        </div>
        <div class="layui-col-md3">
        <div class="layui-form-item">
            <div class="layui-input-group">
              <div class="layui-input-split layui-input-prefix">
                配置说明
              </div>
              <input type="text"  name="des[]" lay-verify="required" placeholder="请输入" class="layui-input">
            </div>
        </div>
        </div>
        <div class="layui-col-md3">
        <div class="layui-form-item">
            <div class="layui-input-group">
              <div class="layui-input-split layui-input-prefix">
                配置值
              </div>
              <input type="text"  name="val[]" placeholder="请输入" class="layui-input">
            </div>
        </div>
        </div>


</div>

        <div class="layui-col-md1">
        <div class="layui-inline" style="left: 5%; top: inherit ">
        <a href="javascript:;" class="layui-btn layui-btn-danger del_item">
            <i class="layui-icon layui-icon-delete"></i>删</a>
        </div>
    </div>

</div>
</script>

<div class="layui-row">

    <div id="dirlist-tree" lay-filter="dirlist-tree" class="layui-col-md2">
        <div class="layui-card">
        <div class="layui-card-body">
        <blockquote class="layui-elem-quote">请点击下面的插件增加修改配置</blockquote>
            <ul class="layui-menu">
                {% for i in pluglist %}
                <li class="layui-menu-body-title"><a href="javascript:;" class="loadjson" apdata="{{ i }}">[{{ i }}]</a></li>
                {% endfor %}
            </ul>
        </div>
        </div>
    </div>

        <div class="layui-col-md10" id="aceeditor">
            <div class="layui-card">
            <div class="layui-card-body">
            <div>当前应用:<span id="appname">请选择左侧应用</span></div>
<form class="layui-form" action="/dev/conf/ajax_savejson" method="post" id="form_conf">
    <div id="formbody"></div>

    <div class="layui-form-item actionbox" style="display: None;">
    <div class="layui-input-block">
        <input type="hidden" id="app" name="app" value="">
      <button type="button" class="layui-btn layui-btn-normal" id="addConfItem">添加选项</button>
      <button type="button" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="updateconf">立即提交</button>
    </div>
  </div>
</form>
        </div>
    </div>
            </div>
</div>


<script type="text/javascript" src="{{ url_for('dev.static', filename='formbuilder/layui/layui.js') }}"></script>
<script>
    layui.use(['form','jquery','layer'], function(){
        let $ = layui.jquery
        let form = layui.form
        let layer = layui.layer


        $("#addConfItem").click(function(){
            $("#formbody").append($("#confItems").html())
            form.render();
        })

        $('#formbody').on('click','.del_item',function(){
            $(this).parent().parent().parent('.oneline_item').remove()
            form.render();
        })

        $(".loadjson").click(function(){
            app = $(this).attr('apdata')
            {#console.log(app)#}
            $('#app').val(app)
            $("#formbody").html('')
            $.ajax({
                url: 'ajax_getjson',
                data: "app="+app,
                type: 'POST',
                success: function (res) {
                    if(res){
                        $("#formbody").prepend(res)
                        form.render();
                    }
                }
            });
            //$("#formbody").append($("#confItems").html())
            $(".actionbox").show()
            form.render();
        })

        // 提交事件
        form.on('submit(updateconf)', function(data){
            $('#form_conf').submit()
        });
    })
</script>
</body>
</html>